;; noter  (C) Stephen De Gabrielle GPL 2
(module graph mzscheme
  (require 
   (lib "mred.ss" "mred")
   (lib "framework.ss" "framework")
   (lib "graph.ss" "mrlib")
   (lib "class.ss")
   (lib "list.ss")
   (lib "pregexp.ss"))
  ;;;;;;;;;;;;;;;;;;;;
  ;; helper methods ;;
  ;;;;;;;;;;;;;;;;;;;;
  
  ;;;;;;;;;;;;;;;;;;;;;
  ;; GUI definition  ;;
  ;;;;;;;;;;;;;;;;;;;;;
  
  ;;;;;;;;;;;;;;;;;;;;;
  ;; Classes         ;;
  
  
  ;;;;;;;;;;;;;;;;;;;;;
  ;; Objects         ;;
  ;;;;;;;;;;;;;;;;;;;;;
  (define the-the-frame
    (new frame:standard-menus%
         (label "Noter - with incremental")
         (width 600)
         (height 600)))
  
  (define the-frame (send the-the-frame get-area-container))
  
  (send the-frame accept-drop-files #t)
  ;; Add the 'description' text field 
  (define the-text-field (instantiate text-field% (#f the-frame void)))
  
  
  (define the-vertical-pane
    (new panel:vertical-dragable%
         (parent the-frame)))
  ;; add the matching descriptions list box
  (define the-list-box
    (instantiate list-box% ("" '("") the-vertical-pane void)
      (stretchable-height #f)
      (min-height 80)))
  
  (define the-editor-canvas (instantiate editor-canvas% (the-vertical-pane)))
  
  (define the-graph-pasteboard (instantiate (graph-pasteboard-mixin pasteboard:basic%) ()))
  (send the-editor-canvas set-editor the-graph-pasteboard)
  
  (define my-graph-snip% (graph-snip-mixin string-snip%))
  
  
  
  (define (connect parent child)
    (define dark-pen (send the-pen-list find-or-create-pen "blue" 1 'solid))
    (define dark-brush (send the-brush-list find-or-create-brush "blue" 'solid))
    (define light-pen (send the-pen-list find-or-create-pen "light blue" 1 'solid))
    (define light-brush (send the-brush-list find-or-create-brush "light blue" 'solid))
    (add-links parent child
               dark-pen light-pen
               dark-brush light-brush))
  
  (define aaa (make-object my-graph-snip% "aaa")) 
  (define bbb (make-object my-graph-snip% "bbb")) 
  
  (send the-graph-pasteboard insert aaa)
  (send the-graph-pasteboard insert bbb)
  
  (connect aaa bbb)
  (send the-graph-pasteboard move-to bbb 100 100 )
  
  ;; draw-graph : list-of-edges -> list of (vertex x y)
  ;; vertices, name position
  ;; edges; name name
  (define (draw-graph edges)
    (define nodes (filter new-node? (map get-node edge))
    ;set up initial node positions randomly // make sure no 2 nodes are in exactly the same position
    
    loop
    
    )  
  total_kinetic_energy := 0 // running sum of total kinetic energy over all particles
  for each node
  net_force := (0, 0) // running sum of total force on this particular node
  
  for each other node
  net_force := net_force + Coulomb_repulsion( this_node, other_node )
  next node
  
  for each spring connected to this node
  net_force := net_force + Hooke_attraction( this_node, spring )
  next spring
  
  // without damping, it moves forever
  this_node.velocity := (this_node.velocity + timestep * net_force) * damping
  this_node.position := this_node.position + timestep * this_node.velocity
  total_kinetic_energy := total_kinetic_energy + (this_node.velocity)^2
  next node
  until total_kinetic_energy is less than some small number  //the simulation has stopped moving
  
  
  (send the-the-frame show #t) 
  )
